﻿namespace Hotel.ModulesTest
{
    using ManagementModule = Hotel.Module.Management;
    using System.Collections.Generic;
    using Hotel.Module.Management;
    using Hotel.Module.Management.Models;
    using NUnit.Framework;
    using System;

    [TestFixture]
    class GetAssignmentByIDTestClass
    {
        //TODO implement
        [Test]
        public void GetAssignmentByIDTest()
        {
            using (ManagementController m_ManagementController = Hotel.Web.Helpers.ServiceLocator.Instance.GetService(typeof(IManagement)) as ManagementController)
            {
                #region Prepare
                Assignment assToDelete = m_ManagementController.Storage.Find(new Predicate<Assignment>(p => p.Description == "FinishAssignmentTest"));
                if (assToDelete != null)
                {
                    m_ManagementController.Storage.Delete(assToDelete);
                }

                Assignment ass = new Assignment();
                ass.Description = "FinishAssignmentTest";
                ass.RoomNumber = 1;
                ass.ServiceID = 1;
                ass.State = AssignmentState.Applied;
                ass.WorkerLogin = "FinishAssignmentTest";
                ass.WorkerType = Assignment.CurrentWorkerType.Cleaners;
                
                m_ManagementController.Storage.Add(ass);
                m_ManagementController.SaveChanges();

                int _id = m_ManagementController.GetAssignments()[m_ManagementController.GetAssignments().Count-1].ID;
                #endregion

                //Predicate<Assignment> match = m => m.ID == _id;
                ass = (Assignment)m_ManagementController.Storage.Find(new Predicate<Assignment>(m => m.ID == _id));

                Assert.AreEqual(_id, ass.ID);
            }
        }
    }
}
